
*****************************************************************************	
*1990-2014 panel: average effects
*********************************************************************************

clear
set more off
estimates clear
set matsize 10000

*directories

cd "C:\Users\jgw99\Dropbox\hillbilly"
global d = "C:\Users\jgw99\Dropbox\hillbilly\paper_vJAERE"

*data

use annual_data_1990_2014

*outliers 

	gen outlier=(droy_pc>10000)
		replace outlier=0 if year<2009
	bysort fips: egen t_outlier=total(outlier)
	tab fips if t_outlier>0 & year==2014
	drop if t_outlier>0

*county types

gen dqp_25=((dqp/5.05)*50>25000000)	
	la var dqp_25 "County change in O&G production above $25 million, 2000-2014"
gen dqp_250=((dqp/5.05)*50>250000000)
	la var dqp_250 "County change in O&G production above $250 million, 2000-2014"
	
*counting counties

count if shale3==1 & year==2014
count if dqp_25==1 & year==2014
count if dqp_250==1 & year==2014	
	
sort fips year

xtset fips 

	*year variables
	forvalues y=1991(1)2014 {
		gen y`y'=(year==`y')
		gen OG_Growth_x_`y'=(shale3==1 & year==`y')
		gen s3x`y'=(shale3==1 & year==`y')
	}
	
matrix year=1991\1992\1993\1994\1995\1996\1997\1998\1999\2000\2001\2002\2003\2004\2005\2006\2007\2008\2009\2010\2011\2012\2013\2014
global sx s3x1991 s3x1992 s3x1993 s3x1994 s3x1995 s3x1996 s3x1997 s3x1998 s3x1999 s3x2000 s3x2001 s3x2002 s3x2003 s3x2004 s3x2005 s3x2006 s3x2007 s3x2008 s3x2009 s3x2010 s3x2011 s3x2012 s3x2013 s3x2014

*************************************************
*table of coefficient estimates
*************************************************

estimates clear

foreach var in agipc_c wagepc_c nwpc_c {

		qui: xi: xtreg `var' OG_Growth* i.year*i.st, fe cluster(fips)
		estimates store all_s3_`var'
		
		qui: xi: xtreg `var' OG_Growth* i.year*i.st if dqp_25==1 | dqp<=0, fe cluster(fips)
		estimates store dq25_s3_`var'
		
		qui: xi: xtreg `var' OG_Growth* i.year*i.st if dqp_250==1 | dqp<=0, fe cluster(fips)
		estimates store dq250_s3_`var'
	}	
	
*making tables from results 
	
esttab *agipc_c using $d\tot_inc_90_14.tex,  wide b(0) se(0) nonotes keep(OG_Growth*) ///
collabels(none) mtitles("Full Sample" "Subsample 1" "Subsample 2") replace ///
stats(r2_a N, fmt(2 %9.0fc) label(R-squared N)) 
  
esttab *wagepc_c using $d\wage_inc_90_14.tex,  wide b(0) se(0) nonotes keep(OG_Growth**) ///
collabels(none) mtitles("Full Sample" "Subsample 1" "Subsample 2") replace ///
stats(r2_a N, fmt(2 %9.0fc) label(R-squared N))  

esttab *nwpc_c using $d\nw_inc_90_14.tex,  wide b(0) se(0) nonotes keep(OG_Growth**) ///
collabels(none) mtitles("Full Sample" "Subsample 1" "Subsample 2") replace ///
stats(r2_a N, fmt(2 %9.0fc) label(R-squared N))  

******************************************************
*graphing 1990-2014 results
*******************************************************

*total agi

qui: xi: xtreg agipc_c $sx i.year*i.st, fe cluster(fips)

	matrix b=e(b)'
	matrix b=b["s3x1991".."s3x2014", 1]
	matrix d=(vecdiag(e(V)))'
	matrix d=d["s3x1991".."s3x2014", 1]
	matmap d se,map(sqrt(@))
	matrix ci_u=b+1.96*se
	matrix ci_l=b-1.96*se
	matrix r=b,ci_l,ci_u
	svmat r, names(agipc)
	svmat year, names(x)
	
	qui: twoway line agipc1 agipc2 agipc3 x1, ytitle("Dollars Per Capita", size(large) margin(medium)) ylab(-500 (500) 3000, nogrid format(%9.0gc) /*
	*/ labsize(large) angle(0)) yline(0,lstyle(foreground)) ysize(2.2) xtitle("") xlab(1991(2)2013, labsize(large)) xsize(4.5) /*
	*/ legend(off) graphregion(color(white)) lcolor(black black black) lpattern(solid dash dash) lwidth(thick thick thick)  /*
	*/ plotregion(color(white))
	qui:  graph export $d\g_agipc_9014.pdf, replace

*wage and nonwage income

foreach var in wagepc nwpc {
		
qui: xi: xtreg `var'_c $sx i.year*i.st, fe cluster(fips)

	matrix b=e(b)'
	matrix b=b["s3x1991".."s3x2014", 1]
	matrix d=(vecdiag(e(V)))'
	matrix d=d["s3x1991".."s3x2014", 1]
	matmap d se,map(sqrt(@))
	matrix ci_u=b+1.96*se
	matrix ci_l=b-1.96*se
	matrix r=b,ci_l,ci_u
	svmat r, names(`var')
	
	qui: twoway line `var'1 `var'2 `var'3 x1, ytitle("Dollars Per Capita", size(large) margin(medium)) ylab(-500 (500) 2500, nogrid format(%9.0gc) /*
	*/ labsize(large) angle(0)) yline(0,lstyle(foreground)) ysize(2.2) xtitle("") xlab(1991(2)2013, labsize(large)) xsize(4.5) /*
	*/ legend(off) graphregion(color(white)) lcolor(black black black) lpattern(solid dash dash) lwidth(thick thick thick)  /*
	*/ plotregion(color(white))
	graph export "$d\g_`var'_9014.pdf", replace

	}


	
